Skip to content

Conversation

@belimawr
Copy link
Contributor

@belimawr belimawr commented Nov 7, 2025

What does this PR do?

Because NewTestingLogger used testing.T as the logger output, if the logger is used after the test has ended, it will panic.

This behaviour has been seen a few times and causes flakiness in our CI.

To mitigate this, NewTestingLogger now just calls NewFileLogger that uses a file as the logger output, thus being safe for use even after the test has ended.

Why is it important?

It prevents tests from becoming flaky

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works

## Author's Checklist
## Related issues

Because NewTestingLogger used testing.T as the logger output, if the
logger is used after the test has ended, it will panic.

This behaviour has been seen a few times and causes flakiness in our
CI.

To mitigate this, NewTestingLogger now just calls NewFileLogger that
uses a file as the logger output, thus being safe for use even after
the test has ended.
@belimawr belimawr requested a review from a team as a code owner November 7, 2025 15:11
@belimawr belimawr requested review from AndersonQ, orestisfl and rdner and removed request for a team November 7, 2025 15:11
@elasticmachine
Copy link
Collaborator

elasticmachine commented Nov 7, 2025

@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Nov 7, 2025
@rdner rdner requested a review from khushijain21 November 7, 2025 15:18
Comment on lines +33 to +34
// DEPRECATED: The logger returned by [NewTestingLogger] can panic if it is
// used after the test has ended. Use [NewFileLogger] instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't do this, the testing logger is integrated in the stdlib testing infra.

The panic is exposing a bug in the code, that's where it should be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created elastic/beats#47527 to track the failing tests because of the logger issue.

@mauri870
Copy link
Member

mauri870 commented Nov 12, 2025

I honestly think this PR is unnecessary. The panic occurs because there are calls to t.Log after the test has finished, which in this case happen when actual code tries to invoke logger methods. This is a symptom of missing synchronization, we don't properly ensure that shutdown completes before the test ends. As a result, some components are still running or cleaning up after the test has finished. This indicates either a bug or carelessness, and in both cases, it should be fixed. This is especially important for Beats receivers, which have a well-defined startup and shutdown procedure.

@belimawr
Copy link
Contributor Author

Thanks for the feedback folks, I'll close the PR.

@belimawr belimawr closed this Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants